package com.lfg.leetcode.leetcode200;


import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class No299getHint {


    public static void main(String[] args) {
        System.out.println(getHint("1123", "0111"));
    }

    public static String getHint(String secret, String guess) {
        StringBuilder ret = new StringBuilder();

        if (null == secret || null == guess) {
            return "0A0B";
        }

        int a = 0;
        int b = 0;

        int[] b1 = new int[10];
        int[] b2 = new int[10];

        int length = secret.length();
        Map<Character, Set<Integer>> data = new HashMap<>(length);
        Map<Character, Integer> cnt = new HashMap<>(length);
        for (int i = 0; i < length; i++) {
            Character c1 = secret.charAt(i);
            Character c2 = guess.charAt(i);
            if (c1 == c2) {
                a++;
            } else {
                b1[c1 - '0']++;
                b2[c2 - '0']++;
            }
        }

        for (int i = 0; i < 10; i++) {
            b += Math.min(b1[i], b2[i]);
        }

        ret.append(a).append('A').append(b).append('B');
        return ret.toString();
    }
}

